home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_04 / allison / convert3.cpp < prev    next >
C/C++ Source or Header  |  1995-02-06  |  413b  |  36 lines

  1. LISTING 3 - Illustrates an implicit user-defined conversion
  2.  
  3. // convert3.cpp
  4. #include <iostream.h>
  5.  
  6. struct A
  7. {
  8.     double x;
  9.  
  10.     A(double d)
  11.     {
  12.         cout << "A::A(double)" << endl;
  13.         x = d;
  14.     }
  15. };
  16.  
  17. void f(const A& a)
  18. {
  19.     cout << "f: " << a.x << endl;
  20. }
  21.  
  22. main()
  23. {
  24.     A a(1);
  25.     f(a);
  26.     f(2);
  27.     return 0;
  28. }
  29.  
  30. // Output:
  31. A::A(double)
  32. f: 1
  33. A::A(double)
  34. f: 2
  35.  
  36.